/**
 * 
 */
package ws;

import java.util.ArrayList;
import java.util.Collection;
import org.orm.PersistentException;
import SOAPVO.AlumnoSOAPVO;
import com.google.gson.Gson;

/**
 * @author Killua
 *
 */
public class Alumnos {
	
		
		/*
		 * @return
		 */
		
		public String buscarAlumnos (String nombre){
		
			String json = null;
			
	        
			orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
			Collection<AlumnoSOAPVO> coleccionAlumnos = new ArrayList<AlumnoSOAPVO>();
	        orm.Tan_alumno[] ormAlumno;
			
	        if((nombre == null) || (nombre == (""))){
	        	
	        	json = "0";        	
	        }
	        
	        else{
	        	
	        	try{
	        		ormAlumno = lDAOFactory.getTan_alumnoDAO().listTan_alumnoByQuery("al_nombre like'%"+nombre+"%'", null);
	                if (ormAlumno.length == 0) {
	                    json = "1";
	                }
	                else{
	                	for (int i = 0; i < ormAlumno.length; i++ ){
	                        AlumnoSOAPVO alumnoencontrado = AlumnoSOAPVO.crearAlumnoSOAPVO(ormAlumno[i]);
	                        coleccionAlumnos.add(alumnoencontrado);
	                        System.out.println("alumno :"+ormAlumno[i]);
	                       
	                	}
	                    Gson gson = new Gson();
	                    json = gson.toJson(coleccionAlumnos);
	                }
	        	}
	        	catch (PersistentException e){
	        		e.printStackTrace();
	        		json = "2";        	
	        	}
			
	        } 
	        return json;  
		}
		
		
		
	}

